

const webpack = require('webpack');
const moment = require('moment')
process.env.VUE_APP_TIME = moment().format('YYYY.MM.DD hh:mm:ss')
const ASSET_PATH = process.env.VUE_APP_TIME|| ' ';

module.exports = {
     publicPath: "",    // 只有请求静态资源的时候会在url上拼接，实际的接口请求的时候并不会拼接上去
     css:{
          sourceMap :true,
          loaderOptions:{
               // sass:{
               //   prependData:`@import "./assets/scss/_custom.scss"`
               // }
               less: {
                    javascriptEnabled: true,
               },
          },
     },

     lintOnSave: false,
     runtimeCompiler: true,
     productionSourceMap: false,
     configureWebpack: {
          resolve: {
               symlinks: false
          },
          plugins:[
               new webpack.ProvidePlugin({
                    $: 'jquery',
                    jquery: 'jquery',
                    'window.jQuery': 'jquery',
                    jQuery: 'jquery'
               }),
               //配置全局变量
               new webpack.DefinePlugin({
                    'buildTime': JSON.stringify(ASSET_PATH),
               })
          ]
     },

     // 配置开发 跨域请求 和 模块服务地址
     devServer: {
          port: "8080", //端口号
          host: "",
          open: true, //配置自动启动浏览器
          proxy: {
               '/': {  
                    // 除登录外所有请求
                    //【123.249.89.204】 临时测试地址
                    //【172.16.40.43】  测试地址
                    target: 'http://172.17.102.36:30800',//nginx跨域请求头信息
                    secure: false, // 如果是https接口，需要配置这个参数
                    // pathRewrite: {'^/testUser': ''}
               },
          }
     },
}




/*

//cnpm install uglifyjs-webpack-plugin --save-dev

const webpack = require('webpack');
const UglifyPlugin = require("uglifyjs-webpack-plugin");
const path = require("path");
module.exports = {
     publicPath: '',
     css: {
          sourceMap: true,
          loaderOptions: {}
     },
     lintOnSave: false,
     productionSourceMap: false,
     runtimeCompiler: false,
     configureWebpack: config => {
          if (process.env.NODE_ENV === "production") {
               // 为生产环境修改配置...
               config.mode = "production";
               // 将每个依赖包打包成单独的js文件
               var optimization = {
                    runtimeChunk: "single",
                    splitChunks: {
                         chunks: "all",
                         maxInitialRequests: Infinity,
                         minSize: 200, // 依赖包超过20000bit将被单独打包
                         cacheGroups: {
                              vendor: {
                                   test: /[\\/]node_modules[\\/]/,
                                   name(module) {
                                        const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
                                        return `npm.${packageName.replace("@", "")}`;
                                   }
                              }
                         }
                    },
                    minimizer: [

                        /!* new UglifyPlugin({
                              uglifyOptions: {
                                   compress: {
                                        warnings: false,
                                        drop_console: true, // console
                                        drop_debugger: false,
                                        pure_funcs: ["console.log"] // 移除console
                                   }
                              },
                             /!* exclude: "@coreui/coreui-free-vue-admin-template@3.0.0-beta.3",*!/
                         })
*!/
                    ]
               };
               //合并配置到config中
               Object.assign(config, {optimization});
          } else {
               // 为开发环境修改配置...
               config.mode = "development";
               var optimization1 = {
                    runtimeChunk: "single",
                    splitChunks: {
                         chunks: "all",
                         maxInitialRequests: Infinity,
                         minSize: 20000, // 依赖包超过20000bit将被单独打包
                         cacheGroups: {
                              vendor: {
                                   test: /[\\/]node_modules[\\/]/,
                                   name(module) {
                                        const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
                                        return `npm.${packageName.replace("@", "")}`;
                                   }
                              }
                         }
                    }
               };
               Object.assign(config, {optimization: optimization1});
          }
          // 开发生产共同配置 ,合并配置到config中
          Object.assign(config, {
                    resolve: {
                         extensions: [".js", ".vue", ".json"], //文件优先解析后缀名顺序
                         alias: {
                              "@": path.resolve(__dirname, "./src"),
                              "@c": path.resolve(__dirname, "./src/components"),
                              "@v": path.resolve(__dirname, "./src/views"),
                              "@u": path.resolve(__dirname, "./src/utils"),
                              "@s": path.resolve(__dirname, "./src/service"),
                         }, // 别名配置
                         plugins: []
                    },
               }
          );
          config.plugins.push(
               new webpack.ProvidePlugin({
                    jquery: "jquery",
                    $: "jquery",
                    "windows.jQuery":"jquery",
                    jQuery: 'jquery',
               })
          )
     },
};
*/
